﻿#ifndef CDevDataCam_H
#define CDevDataCam_H
/********************************************************************************
** @ Date:2025/04/17
** @ Author: HanJiaXin
** @ Description:摄像头设备数据类
** @ Version:1.0.0
** @ ClassName:
** @ Fun:
********************************************************************************/
#include <QJsonObject>
#include <QXmlStreamReader>
#include "Header.h"
#include "HCNetSDK.h"
#include "CMeasurePoint.h"

struct STRU_CHANNEL_INFO
{
	char    chChanName[40];     //通道名称
	int		iChanIndex;			//监控通道号 = 数组索引+startchan
	int		iPicResolution;	    //图片分辨率
	int		iPicQuality;	    //图片质量
	char	chAccessChanIP[16]; //ip接入通道的ip地址
	bool    bEnable;            //是否有效
	NET_DVR_DECODERCFG_V30  struDecodercfg;   //通道的解码器信息
	STRU_CHANNEL_INFO()
	{
		chChanName[0] = '\0';
		iChanIndex = -1;
		iPicResolution = 0;
		iPicQuality = 2;
		chAccessChanIP[0] = '\0';
		bEnable = false;
	}
};

struct STRU_DEVICE_INFO
{
	long    lLoginID;
	int		iDeviceChanNum;		    //设备的通道数
	int		iStartChan;				//设备开始通道号
	int 	iIPChanNum;				//最大数字通道个数
	int 	iIPStartChan;			//数字通道起始通道号
	int		iEnableChanNum;			//有效通道数
	bool    bIPRet;                 //是否支持ip接入

	STRU_CHANNEL_INFO struChanInfo[MAX_CHANNUM_V30];


	LONG lDefenseHandle;//布防Handle addwxy


	STRU_DEVICE_INFO()
	{
		lLoginID = -1;
		iDeviceChanNum = -1;
		iStartChan = 0;
		iIPChanNum = 0;
		iEnableChanNum = -1;
		bIPRet = FALSE;
		lDefenseHandle = 0;//布防Handle addwxy
	}
};

struct SCamerInfo
{
	NET_DVR_CLIENTINFO m_cClientInfo;           //软解码预览参数结构体对象
	int                m_nDevTypeCode;          //相机设备类型编码   
	bool               m_bConStatus;            //设备连接状态    0未连接  1已连接 
	bool               m_bIsRecording;          //是否正在录像
	bool               m_bIsVoiceRecording;     //是否正在录音
	LONG               m_lHandle;               //视频播放句柄  
	LONG               m_lVoiceHandle;			//语音对讲句柄
	LONG               m_lVoiceForwardHandle;	//语音转发句柄
	QString            m_sRtspUrl;              //rtsp视频流
	SCamerInfo()
	{
		m_nDevTypeCode = 0;
		m_bConStatus = false;
		m_bIsRecording = false;
		m_bIsVoiceRecording = false;
		m_lHandle = -1;
		m_lVoiceHandle = -1;
		m_sRtspUrl = "";
	}
	//复位数据
	void resetData()
	{
		m_nDevTypeCode = 0;
		m_bConStatus = false;
		m_bIsRecording = false;
		m_bIsVoiceRecording = false;
		m_lHandle = -1;
		m_lVoiceHandle = -1;
		m_sRtspUrl = "";
	}
};

struct AlarmItem
{
	QString sGuid;
	QString sCamerName;
	QString sAlarmType;
	QString sAlarmTime;
	int nAlarmLevel;
	int nIsConfirm;
	QString sUrl;
	AlarmItem()
	{
		sGuid = "";
		sCamerName = "";
		sAlarmType = "";
		sAlarmTime = "";
		nAlarmLevel = 1;
		nIsConfirm = 0;
		sUrl = "";
	}
};

// 定义报警数据结构
class AlarmData 
{
public:
	bool bIsValid = true;//是否有效
	QDateTime dateTime;// 事件时间
	QString ipAddress;// 设备IP
	int portNo;// 端口
	QString eventState;// 事件状态
	int presetNo;// 预置位
	QString eventType; // 事件类型
	QString eventDescription; // 事件描述
	QString MPID; // 模型ID
	QString MPName;// 模型名称
	int channelID;// 通道ID
	QString url;//图片url
	int     degree;
	QString sRuleName;//规则名
	// AIOP数据
	struct AIOPData 
	{
		// 事件信息
		struct Events 
		{
			QList<QJsonObject> alertInfo;
		} events;
	} aiopData;

	// 从JSON解析
	static AlarmData fromJson(const QJsonObject &json);
	static AlarmData fromKYJson(const QJsonObject &json);

	// 从XML解析
	static AlarmData fromXml(QString sXml);
};

class CDevDataCam
{
public:
	CDevDataCam();
	~CDevDataCam();

public:
	QMutex*  m_pMutex;						//数据锁
	QString  m_sDevGuid;					//归属设备Guid
	bool     m_bInit;                       //云台设备是否已经初始化
	bool     m_bLogin;                      //云台设备是否连接
	bool     m_bLoginValue;					//云台设备是否连接测点值
	QString  m_sCamerName;					//云台名称
	QString  m_sServerIp;					//归属算法服务器Ip地址
	QString  m_sCamerIp;                    //云台ip
	int      m_nCamerPort;                  //云台端口号
	int      m_nVideoType;					//摄像头类型0:单目摄像头 1:双目摄像头
	int      m_nChannel;					//摄像头在AI服务器中的通道号
	int      m_nChannelHW;					//红外在AI服务器中的通道号
	QString  m_sUserName;                   //用户名
	QString  m_sPassWord;                   //密码
	QString  m_sRecordPath;					//手动录像拍照保存的路径
	QString m_sRtspUrlImg;                  //可见光rtsp视频地址
	QString m_sRtspUrlIr;                   //红外rtsp视频地址
	QVector<int> m_vecAlgType;				//摄像头支持算法类型集合

	bool m_bCoalFlow;						//煤流量是否报警
	bool m_bBeltForeign;					//皮带异物是否报警
	bool m_bLargeCoal;						//大块煤是否报警
	bool m_bBeltDeviation;					//皮带跑偏是否报警
	bool m_bSafetyHelmet;					//安全帽反光衣是否报警
	bool m_bSmokeFire;						//烟雾火点是否报警
	bool m_bSmokeMakeCall;					//抽烟打电话是否报警
	bool m_bTemp;							//测温是否报警
	bool m_bPerimeter;						//周界防范是否报警
	bool m_bBlock;							//传送带堵料识别
	bool m_bThrow;							//抛洒滴漏
	bool m_bStreet;							//街面行为

	bool m_bBeltRun;						//皮带启停信号

	QDateTime m_dLastCoalFlow;				//上次煤流量报警时间
	QDateTime m_dLastBeltForeign;			//上次皮带异物报警时间
	QDateTime m_dLastLargeCoal;				//上次大块煤报警时间
	QDateTime m_dLastBeltDeviation;			//上次皮带跑偏报警时间
	QDateTime m_dLastSafetyHelmet;			//上次安全帽反光衣报警时间
	QDateTime m_dLastSmokeFire;				//上次烟雾火点报警时间
	QDateTime m_dLastSmokeMakeCall;			//上次抽烟打电话报警时间
	QDateTime m_dLastTemp;					//上次抽烟打电话报警时间
	QDateTime m_dLastPerimeter;				//上次周界防范报警时间
	QDateTime m_dLastBlock;					//上次堵料报警时间
	QDateTime m_dLastThrow;					//上次抛洒滴漏时间
	QDateTime m_dLastStreet;				//上次街面行为时间

	QDateTime m_dBeltRun;					//上次皮带启停信号时间

	QVector<AlarmItem> m_vecAlarm;			//报警记录集合
	QMap<EDevPointType, CMeasurePoint*> m_mapDevPoint;//测点集合
	QMap<QString, QString> m_mapInputPointAddr;//key:输入测点唯一标识，value输入测点地址
	QMap<QString, CMeasurePoint*> m_mapInputPoint;
	STRU_DEVICE_INFO m_sStruDeviceInfo;
	QMap<int, SCamerInfo> m_cMapCamerInfo;//设备状态数据 给无画面执行任务录像使用 每一个设备对应一个对象 int 设备id 如红外相机  图像相机和语音设备
};

#endif